<?php
/**
 * (commands) Amazon订单(xml) (功能暂未使用)
 */
namespace App\Console\Commands\SpApi\Report\CreateAndGet;

use App\Crontab\Daily\SpApi\GrabCreateReport;
use App\Logic\Amazon\Api\ReportWork;
use Illuminate\Console\Command;

class AllOrdersReport extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'sp-order:get-orders-report {startDate=null} {endDate=null} {accountId=0}';

    /**
     * The console command description.
     * @var string
     */
    protected $description = 'exe func';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     */
    public function handle(){

        $startDate  = $this->argument('startDate');
        $endDate    = $this->argument('endDate');
        $accountId  = $this->argument('accountId');
        $reportType = 'GET_XML_ALL_ORDERS_DATA_BY_ORDER_DATE_GENERAL';

        //账号
        $where = [];
        if($accountId){
            $where['id'] = $accountId;
        }

        //日期 (默认日期：昨天)
        $startDates = $startDate == 'null' ? date('Y-m-d', strtotime("-1 days")) : $startDate;
        $endDates = $endDate == 'null' ? date('Y-m-d', strtotime("-1 days")) : $endDate;
        if (!strtotime($startDates) || !strtotime($endDates)) return false;

        $bof = strtotime($startDates); //开始
        $eof = strtotime($endDates); //结束
        while(true){
            if ($bof > $eof) break;
            $time = $bof;
            $startTime = getDateFormat(date('Y-m-d 00:00:00', $time));
            $endTime = getDateFormat(date('Y-m-d 23:59:59', $time));

            $paramData = [
                'report_type' => $reportType,
                'data_start_time' => $startTime,
                'data_end_time' => $endTime
            ];

            //GrabCreateReport::grab($paramData,$where);
            print_r($paramData);

            $bof += 86400; //+1天
            sleep(2);
        }
        $this->info('finish!');

        //ReportWork::createOrdersReportData($paramData, $multi);
        //$this->info('finish!');
    }

}
